package com.amigo.online.provider.merchant.config;

import java.net.UnknownHostException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;

import com.mongodb.MongoClientURI;

@Configuration
public class MongoConfig {

//	@Value("${spring.data.mongodb.goods.read.uri}")	
//	private String mongoGoodsReadUri;

    @Value("${spring.data.mongodb.merchant.read.uri}")
    private String mongoMerchantReadUri;

    @Bean
    public MongoMappingContext mongoMappingContext() {
        MongoMappingContext mappingContext = new MongoMappingContext();
        return mappingContext;
    }

//	@Bean
//	@Primary
//	public MongoDbFactory dbGoodsReadFactory() throws UnknownHostException {
//		return new SimpleMongoDbFactory(new MongoClientURI(mongoGoodsReadUri));
//	}

//	@Bean("readGoodsMongoTemplate")
//	@Primary
//	public MongoTemplate readGoodsMongoTemplate() throws Exception {
//		return new MongoTemplate(this.dbGoodsReadFactory());
//	}

    @Bean
    public MongoDbFactory dbMerchantReadFactory() throws UnknownHostException {
        return new SimpleMongoDbFactory(new MongoClientURI(mongoMerchantReadUri));
    }

    @Bean("readMerchantMongoTemplate")
    public MongoTemplate readMerchantMongoTemplate() throws Exception {
        return new MongoTemplate(this.dbMerchantReadFactory());
    }


}
